﻿using System;
using Macds.Core.Mapping;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Macds.Test.Core.Mapping
{
    [TestClass]
    public class MappingFactoryTest
    {
        [TestMethod]
        public void Map_property_from_entity()
        {
            // Create new instance of the entity
            var entity = new Mocks.CustomerEntity() { FirstName = "John", LastName = "Smith" };

            // map properties from entity to the customer model class
            var customerModel = MappingFactory.ConvertFromObjectToMapped<Mocks.CustomerModel>(entity);

            // Validate properties
            Assert.AreEqual(entity.FirstName, customerModel.Name);
            Assert.AreEqual(entity.LastName, customerModel.LastName);
        }

        [TestMethod]
        public void Map_property_from_model()
        {
            // Create new instance of the model
            var customerModel = new Mocks.CustomerModel() { Name = "John", LastName = "Smith" };

            // map properties from model to the customer entity class
            var entity = MappingFactory.ConvertFromMappedToObject<Mocks.CustomerEntity>(customerModel);

            // Validate properties
            Assert.AreEqual(entity.FirstName, customerModel.Name);
            Assert.AreEqual(entity.LastName, customerModel.LastName); 
        }

        [TestMethod]
        public void Map_property_to_querystring()
        {
            // Create the new instance of the model
            var order = new Mocks.OrderModel() { OrderID = 1, Amount = 10, CustomerID = 1 };

            // map properties from model to querystring
            string queryString = MappingFactory.GetQueryStringFromObject(order);

            // Validate properties
            Assert.AreEqual("id=1&amount=10&customerID=1", queryString);
        }
    }
}
